package com.seaside.park.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter;
import org.springframework.security.oauth2.config.annotation.web.configurers.ResourceServerSecurityConfigurer;

@Configuration
@EnableResourceServer
@EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true)//激活方法上的PreAuthorize注解
public class ResourceServerConfig extends ResourceServerConfigurerAdapter {
	
    //Http安全配置，对每个到达系统的http请求链接进行校验
    @Override
    public void configure(HttpSecurity http) throws Exception {
        //所有请求必须认证通过
        http.authorizeRequests()
                //下边的路径放行
                .antMatchers("/exhibition/**", "/registration/**",
                        "/swagger-resources", "/swagger-resources/configuration/security",
                        "/swagger-ui.html", "/swagger-ui/**", "/static/**",
                        "/api/user/reg/**","/api/navi/**","/api/notice/**","/api/info/**",
                        "/api/user/login/**", "/api/status/**",
                        "/api/rule/**", "/api/stream_info/**", "/api/label_value/**",
                        "/api/notify/**","/api/public/**","/api/test/**","/WeiXinApi/**","/shareCabinet/**",
                        "/api/car-reception/**", "/api/park-locker/**", "/api/move-order/**", "/api/parking-place-deal/**",
                        "/carStatus/**").permitAll()
                .anyRequest().authenticated();
    }

    @Override
    public void configure(ResourceServerSecurityConfigurer resources) throws Exception {
        resources.resourceId("mobile-resource");
    }
}